/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package service;

import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.Persistence;
import javax.persistence.Query;
import entity.Customer;

/**
 *
 * @author cyhiew
 */
public class CustomerService {
    public static List getCustomerList() {
        
        EntityManager entityManager = Persistence.createEntityManagerFactory("lordwebappPU").createEntityManager();
        Query query = entityManager.createNamedQuery("Customer.findAll");
        List<Customer> resultList = query.getResultList();
        for (Customer c : resultList) {
          System.out.println(c.getName() + " (" + c.getCity() + ")" + "\n");
        }
            
        return resultList;

    }
    
    public static List getCustomerListByID(Integer id) {
        
        EntityManager entityManager = Persistence.createEntityManagerFactory("lordwebappPU").createEntityManager();
        Query query = entityManager.createNamedQuery("Customer.findByCustomerId").setParameter("customerId", id);
        List<Customer> resultList = query.getResultList();
        for (Customer c : resultList) {
          System.out.println(c.getName() + " (" + c.getCity() + ")" + "\n");
        }
            
        return resultList;

    }
}
